package top.as.sean.api.config;

import org.springframework.web.servlet.HandlerInterceptor;
import top.as.sean.common.exception.GlobalException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器
 *
 * @author: ArchieSean
 * @create: 2023/2/12
 */
public class AppInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String method = request.getMethod();
        String uri = request.getRequestURI();
        if ("OPTIONS".equals(method) || "GET".equals(method) || uri.contains("login") || uri.contains("out")) {
            return Boolean.TRUE;
        } else {
            throw new GlobalException("演示环境，不可操作");
        }
    }
}
